package states;

import monitor.StateVariableMonitor;
import gui.OpCom;
import regulators.BallAndBeamRegul;
import regulators.BeamRegul;
import se.lth.control.realtime.DigitalIn;
import se.lth.control.realtime.DigitalOut;
import stateMachine.StateMachine;

/*
 * States implemented as classes
 */

public class InitialState extends StateClass implements State {



	public InitialState(DigitalIn initialPosSensor, DigitalOut digitalSolenoid, BeamRegul beam,
			BallAndBeamRegul ballAndBeam, OpCom op, StateVariableMonitor stateVariableMonitor) {
		super(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor);

	}

	@Override
	public void initialExcecution() {
		op.displayStep("InitialState");

		try{
			digitalSolenoid.set(true);
		} catch (Exception e) {
			e.printStackTrace();
		}

		if(!beam.isAlive()) {
			beam.start();
		}

		if(!ballAndBeam.isAlive()) {
			ballAndBeam.start();
		}

		ballAndBeam.shutDown();
		beam.shutDown();
		beam.setRef(1);
	}

	@Override
	public void excecute() {

	}

	@Override
	public boolean stateOfExcecution() {
		return true;
	}


	@Override
	public void nextState() {
		setCurrentState(new Beam(initialPosSensor, digitalSolenoid, beam, ballAndBeam,op, stateVariableMonitor)); 

	}

	@Override
	public void suspend() {	
		beam.shutDown();
		ballAndBeam.shutDown();		
	}

	@Override
	public void resume() {
		this.initialExcecution();
	}

}